home *** CD-ROM | disk | FTP | other *** search
- package com.ibm.xml.parsers;
-
- import com.ibm.xml.dom.AttrImpl;
- import com.ibm.xml.dom.DeferredDocumentImpl;
- import com.ibm.xml.dom.DocumentImpl;
- import com.ibm.xml.dom.DocumentTypeImpl;
- import com.ibm.xml.dom.ElementDefinitionImpl;
- import com.ibm.xml.dom.EntityImpl;
- import com.ibm.xml.dom.NodeImpl;
- import com.ibm.xml.dom.TextImpl;
- import com.ibm.xml.framework.AttrPool;
- import com.ibm.xml.framework.ElementDeclPool;
- import com.ibm.xml.framework.EntityPool;
- import com.ibm.xml.framework.ParserState;
- import com.ibm.xml.framework.StringPool;
- import com.ibm.xml.framework.XMLParser;
- import java.io.IOException;
- import java.util.Stack;
- import org.w3c.dom.Comment;
- import org.w3c.dom.Document;
- import org.w3c.dom.DocumentType;
- import org.w3c.dom.Element;
- import org.w3c.dom.Entity;
- import org.w3c.dom.EntityReference;
- import org.w3c.dom.NamedNodeMap;
- import org.w3c.dom.Node;
- import org.w3c.dom.NodeList;
- import org.w3c.dom.Notation;
- import org.w3c.dom.ProcessingInstruction;
- import org.w3c.dom.Text;
- import org.xml.sax.AttributeList;
- import org.xml.sax.InputSource;
- import org.xml.sax.SAXException;
-
- public class NonValidatingDOMParser extends XMLParser {
- public static final int FULL = 0;
- public static final int DEFERRED = 1;
- public static final String DEFAULT_DOCUMENT_CLASS;
- private static final boolean DEBUG_ATTLIST_DECL = false;
- protected int fDocumentIndex = -1;
- protected int fDocumentTypeIndex = -1;
- protected int fCurrentNodeIndex = -1;
- protected DocumentType fDocumentType;
- protected Node fCurrentNode;
- protected Stack fNodeStack = new Stack();
- protected Document fDocument;
- protected DocumentImpl fDocumentImpl;
- protected DeferredDocumentImpl fDeferredDocumentImpl;
- protected boolean fExpandEntityReferences = false;
- protected int fNodeExpansion = 1;
- protected boolean fWithinElement = false;
- int fAmpIndex = -1;
- int fLtIndex = -1;
- int fGtIndex = -1;
- int fAposIndex = -1;
- int fQuotIndex = -1;
- protected AttrPool fAttrPool;
- protected ElementDeclPool fElementDeclPool;
- protected EntityPool fEntityPool;
- protected StringPool fStringPool;
- protected String fDocumentClass;
- protected boolean fRootElement;
- private int[] nodestack;
- private int stacktop;
- // $FF: synthetic field
- static Class class$com$ibm$xml$dom$DocumentImpl;
-
- public NonValidatingDOMParser() {
- this.fDocumentClass = DEFAULT_DOCUMENT_CLASS;
- this.nodestack = new int[16];
- ((XMLParser)this).setDocumentHandler(this);
- ((XMLParser)this).setDocumentTypeHandler(this);
- this.fExpandEntityReferences = false;
- this.fNodeExpansion = 1;
- ParserState var1 = ((XMLParser)this).getParserState();
- var1.useDefaultStringPool();
- var1.useDefaultAttrPool();
- var1.useDefaultEntityPool();
- var1.useDefaultElementDeclPool();
- this.init(var1);
- }
-
- public void reset() {
- super.reset();
- this.init(((XMLParser)this).getParserState());
- }
-
- protected void resetOrCopy() {
- super.resetOrCopy();
- this.init(((XMLParser)this).getParserState());
- }
-
- protected void init(ParserState var1) {
- this.fDocumentType = null;
- this.fCurrentNode = null;
- this.fNodeStack.removeAllElements();
- this.fDocumentIndex = -1;
- this.fDocumentTypeIndex = -1;
- this.fCurrentNodeIndex = -1;
- this.fDocumentImpl = null;
- this.fDocument = null;
- this.fWithinElement = false;
- this.fAttrPool = var1.getAttrPool();
- this.fElementDeclPool = var1.getElementDeclPool();
- this.fEntityPool = var1.getEntityPool();
- this.fStringPool = var1.getStringPool();
- this.fAmpIndex = this.fStringPool.addSymbol("amp");
- this.fLtIndex = this.fStringPool.addSymbol("lt");
- this.fGtIndex = this.fStringPool.addSymbol("gt");
- this.fAposIndex = this.fStringPool.addSymbol("apos");
- this.fQuotIndex = this.fStringPool.addSymbol("quot");
- }
-
- protected void checkHandlers() throws Exception {
- super.checkHandlers();
- }
-
- public void setExpandEntityReferences(boolean var1) {
- this.fExpandEntityReferences = var1;
- }
-
- public boolean getExpandEntityReferences() {
- return this.fExpandEntityReferences;
- }
-
- public void setNodeExpansion(int var1) {
- if (var1 != 0 && var1 != 1) {
- this.fNodeExpansion = 1;
- } else {
- this.fNodeExpansion = var1;
- }
- }
-
- public int getNodeExpansion() {
- return this.fNodeExpansion;
- }
-
- public Node getCurrentNode() {
- return this.fCurrentNode;
- }
-
- public void doctypeDecl(int var1) throws Exception {
- if (this.fNodeExpansion == 0) {
- if (this.fDocumentImpl != null) {
- String var2 = this.fStringPool.toString(var1);
- this.fDocumentType = this.fDocumentImpl.createDocumentType(var2);
- this.fDocumentImpl.appendChild(this.fDocumentType);
- this.fCurrentNode = this.fDocumentType;
- return;
- }
- } else if (this.fNodeExpansion == 1) {
- this.fDocumentTypeIndex = this.fDeferredDocumentImpl.createDocumentType(var1);
- this.fDeferredDocumentImpl.appendChild(this.fDocumentIndex, this.fDocumentTypeIndex);
- this.fCurrentNodeIndex = this.fDocumentTypeIndex;
- }
-
- }
-
- public void startInternalSubset() throws Exception {
- }
-
- public void endInternalSubset() throws Exception {
- if (this.fNodeExpansion == 0) {
- this.fCurrentNode = this.fDocument;
- } else {
- if (this.fNodeExpansion == 1) {
- this.fCurrentNodeIndex = this.fDocumentIndex;
- }
-
- }
- }
-
- public void startExternalSubset(int var1, int var2) throws Exception {
- if (this.fNodeExpansion == 0) {
- this.fCurrentNode = this.fDocumentType;
- } else {
- if (this.fNodeExpansion == 1) {
- this.fCurrentNodeIndex = this.fDocumentTypeIndex;
- }
-
- }
- }
-
- public void endExternalSubset() throws Exception {
- if (this.fNodeExpansion == 0) {
- this.fCurrentNode = this.fDocument;
- } else {
- if (this.fNodeExpansion == 1) {
- this.fCurrentNodeIndex = this.fDocumentIndex;
- }
-
- }
- }
-
- public void elementDecl(int var1) throws Exception {
- }
-
- public void attlistDecl(int var1, int var2) throws Exception {
- if (this.fNodeExpansion == 0) {
- if (this.fDocumentImpl != null) {
- int var3 = this.fElementDeclPool.getAttValue(var2);
- if (var3 != -1) {
- int var4 = this.fElementDeclPool.getElementName(var1);
- String var5 = this.fStringPool.toString(var4);
- NamedNodeMap var6 = ((DocumentTypeImpl)this.fDocumentType).getElements();
- ElementDefinitionImpl var7 = (ElementDefinitionImpl)var6.getNamedItem(var5);
- if (var7 == null) {
- var7 = this.fDocumentImpl.createElementDefinition(var5);
- ((DocumentTypeImpl)this.fDocumentType).getElements().setNamedItem(var7);
- }
-
- int var8 = this.fElementDeclPool.getAttName(var2);
- String var9 = this.fStringPool.toString(var8);
- String var10 = this.fStringPool.toString(var3);
- AttrImpl var11 = (AttrImpl)this.fDocumentImpl.createAttribute(var9);
- var11.setValue(var10);
- var11.setSpecified(false);
- var7.getAttributes().setNamedItem(var11);
- return;
- }
- }
- } else if (this.fNodeExpansion == 1) {
- int var12 = this.fElementDeclPool.getAttValue(var2);
- if (var12 != -1) {
- int var13 = this.fElementDeclPool.getElementName(var1);
- int var14 = this.fDeferredDocumentImpl.lookupElementDefinition(var13);
- if (var14 == -1) {
- var14 = this.fDeferredDocumentImpl.createElementDefinition(var13);
- this.fDeferredDocumentImpl.appendChild(this.fDocumentTypeIndex, var14);
- }
-
- int var15 = this.fElementDeclPool.getAttName(var2);
- int var16 = this.fDeferredDocumentImpl.createAttribute(var15, var12, false);
- this.fDeferredDocumentImpl.appendChild(var14, var16);
- }
- }
-
- }
-
- public void internalEntityDecl(int var1) throws Exception {
- int var2 = this.fEntityPool.getEntityName(var1);
- if (this.fNodeExpansion == 0) {
- if (this.fDocumentImpl != null) {
- if (this.fDocumentType == null) {
- return;
- }
-
- Entity var3 = this.fDocumentImpl.createEntity(this.fStringPool.toString(var2));
- this.fDocumentType.getEntities().setNamedItem(var3);
- return;
- }
- } else if (this.fNodeExpansion == 1) {
- if (this.fDocumentTypeIndex == -1) {
- return;
- }
-
- int var4 = this.fDeferredDocumentImpl.createEntity(var1);
- this.fDeferredDocumentImpl.appendChild(this.fDocumentTypeIndex, var4);
- }
-
- }
-
- public void externalEntityDecl(int var1) throws Exception {
- int var2 = this.fEntityPool.getEntityName(var1);
- int var3 = this.fEntityPool.getPublicId(var1);
- int var4 = this.fEntityPool.getSystemId(var1);
- if (this.fNodeExpansion == 0) {
- if (this.fDocumentImpl != null) {
- if (this.fDocumentType == null) {
- return;
- }
-
- EntityImpl var5 = (EntityImpl)this.fDocumentImpl.createEntity(this.fStringPool.toString(var2));
- var5.setPublicId(this.fStringPool.toString(var3));
- var5.setSystemId(this.fStringPool.toString(var4));
- this.fDocumentType.getEntities().setNamedItem(var5);
- return;
- }
- } else if (this.fNodeExpansion == 1) {
- if (this.fDocumentTypeIndex == -1) {
- return;
- }
-
- int var6 = this.fDeferredDocumentImpl.createEntity(var1);
- this.fDeferredDocumentImpl.appendChild(this.fDocumentTypeIndex, var6);
- }
-
- }
-
- public void unparsedEntityDecl(int var1) throws Exception {
- int var2 = this.fEntityPool.getEntityName(var1);
- int var3 = this.fEntityPool.getPublicId(var1);
- int var4 = this.fEntityPool.getSystemId(var1);
- int var5 = this.fEntityPool.getNotationName(var1);
- if (this.fNodeExpansion == 0) {
- if (this.fDocumentImpl != null) {
- if (this.fDocumentType == null) {
- return;
- }
-
- EntityImpl var6 = (EntityImpl)this.fDocumentImpl.createEntity(this.fStringPool.toString(var2));
- var6.setPublicId(this.fStringPool.toString(var3));
- var6.setSystemId(this.fStringPool.toString(var4));
- var6.setNotationName(this.fStringPool.toString(var5));
- this.fDocumentType.getEntities().setNamedItem(var6);
- return;
- }
- } else if (this.fNodeExpansion == 1) {
- if (this.fDocumentTypeIndex == -1) {
- return;
- }
-
- int var7 = this.fDeferredDocumentImpl.createEntity(var1);
- this.fDeferredDocumentImpl.appendChild(this.fDocumentTypeIndex, var7);
- }
-
- }
-
- public void notationDecl(int var1) throws Exception {
- int var2 = this.fEntityPool.getEntityName(var1);
- if (this.fNodeExpansion == 0) {
- if (this.fDocumentImpl != null) {
- if (this.fDocumentType == null) {
- return;
- }
-
- Notation var3 = this.fDocumentImpl.createNotation(this.fStringPool.toString(var2));
- this.fDocumentType.getNotations().setNamedItem(var3);
- return;
- }
- } else if (this.fNodeExpansion == 1) {
- if (this.fDocumentTypeIndex == -1) {
- return;
- }
-
- int var4 = this.fDeferredDocumentImpl.createNotation(var1);
- this.fDeferredDocumentImpl.appendChild(this.fDocumentTypeIndex, var4);
- }
-
- }
-
- public void parameterEntityDecl(int var1) {
- }
-
- public void setDocumentClass(String var1) {
- if (var1 == null) {
- var1 = DEFAULT_DOCUMENT_CLASS;
- }
-
- this.fDocumentClass = var1;
- if (!var1.equals(DEFAULT_DOCUMENT_CLASS)) {
- this.setNodeExpansion(0);
- }
-
- }
-
- public Document getDocument() {
- return this.fDocument;
- }
-
- public void startDocument(int var1, int var2, int var3) {
- if (var1 != -1) {
- this.fStringPool.orphanString(var1);
- }
-
- if (var2 != -1) {
- this.fStringPool.orphanString(var2);
- }
-
- if (var3 != -1) {
- this.fStringPool.orphanString(var3);
- }
-
- if (this.fNodeExpansion == 0) {
- try {
- this.fDocument = (Document)Class.forName(this.fDocumentClass).newInstance();
- if (this.fDocument instanceof DocumentImpl) {
- this.fDocumentImpl = (DocumentImpl)this.fDocument;
- }
- } catch (Exception var4) {
- }
-
- this.fCurrentNode = this.fDocument;
- } else {
- if (this.fNodeExpansion == 1) {
- this.fDocumentImpl = this.fDeferredDocumentImpl = new DeferredDocumentImpl(((XMLParser)this).getParserState());
- this.fDocument = this.fDocumentImpl;
- this.fDocumentIndex = this.fDeferredDocumentImpl.createDocument();
- this.fCurrentNodeIndex = this.fDocumentIndex;
- }
-
- }
- }
-
- public void endDocument() throws Exception {
- }
-
- public void startElement(int var1, int var2) throws Exception {
- this.fRootElement = true;
- if (this.fNodeExpansion == 0) {
- this.fNodeStack.push(this.fCurrentNode);
- String var10 = this.fStringPool.toString(var1);
- AttributeList var11 = this.fAttrPool.getAttributeList(var2);
- Element var12 = this.fDocument.createElement(var10);
- int var6 = var11.getLength();
-
- for(int var7 = 0; var7 < var6; ++var7) {
- var12.setAttribute(var11.getName(var7), var11.getValue(var7));
- }
-
- this.fCurrentNode.appendChild(var12);
- this.fCurrentNode = var12;
- this.fWithinElement = true;
- if (this.fDocumentImpl != null) {
- for(int var8 = this.fAttrPool.getFirstAttr(var2); var8 != -1; var8 = this.fAttrPool.getNextAttr(var8)) {
- if (this.fAttrPool.getAttType(var8) == 1) {
- String var9 = this.fStringPool.toString(this.fAttrPool.getAttValue(var8));
- this.fDocumentImpl.putIdentifier(var9, var12);
- }
- }
- }
-
- this.fAttrPool.releaseAttrList(var2);
- } else {
- if (this.fNodeExpansion == 1) {
- this.push(this.fCurrentNodeIndex);
- int var3 = this.fDeferredDocumentImpl.createElement(var1, var2);
- this.fDeferredDocumentImpl.appendChild(this.fCurrentNodeIndex, var3);
- this.fCurrentNodeIndex = var3;
- this.fWithinElement = true;
-
- for(int var4 = this.fAttrPool.getFirstAttr(var2); var4 != -1; var4 = this.fAttrPool.getNextAttr(var4)) {
- if (this.fAttrPool.getAttType(var4) == 1) {
- int var5 = this.fAttrPool.getAttValue(var4);
- this.fDeferredDocumentImpl.putIdentifier(var5, var3);
- }
- }
- }
-
- }
- }
-
- public void endElement(int var1) throws Exception {
- if (this.fNodeExpansion == 0) {
- this.fCurrentNode = (Node)this.fNodeStack.pop();
- this.fWithinElement = false;
- } else {
- if (this.fNodeExpansion == 1) {
- this.fCurrentNodeIndex = this.nodestack[--this.stacktop];
- this.fWithinElement = false;
- }
-
- }
- }
-
- public void startEntityReference(int var1) throws Exception {
- if (!this.fExpandEntityReferences) {
- int var2 = this.fEntityPool.getEntityName(var1);
- if (var2 != this.fAmpIndex && var2 != this.fGtIndex && var2 != this.fLtIndex && var2 != this.fAposIndex && var2 != this.fQuotIndex) {
- if (this.fNodeExpansion == 0) {
- this.fNodeStack.push(this.fCurrentNode);
- EntityReference var4 = this.fDocument.createEntityReference(this.fStringPool.toString(var2));
- if (var4 != null) {
- this.fNodeStack.push(var4);
- this.fCurrentNode.appendChild(var4);
- this.fCurrentNode = var4;
- }
- } else {
- if (this.fNodeExpansion == 1) {
- this.push(this.fCurrentNodeIndex);
- int var3 = this.fDeferredDocumentImpl.createEntityReference(var1);
- this.push(var3);
- this.fDeferredDocumentImpl.appendChild(this.fCurrentNodeIndex, var3);
- this.fCurrentNodeIndex = var3;
- }
-
- }
- }
- }
- }
-
- public void endEntityReference(int var1) throws Exception {
- if (!this.fExpandEntityReferences) {
- int var2 = this.fEntityPool.getEntityName(var1);
- if (var2 != this.fAmpIndex && var2 != this.fGtIndex && var2 != this.fLtIndex && var2 != this.fAposIndex && var2 != this.fQuotIndex) {
- if (this.fNodeExpansion == 0) {
- if (this.fDocumentImpl != null) {
- NodeImpl var3 = (NodeImpl)this.fNodeStack.pop();
- this.fCurrentNode = (NodeImpl)this.fNodeStack.pop();
- if (var3.getNodeType() != 5) {
- return;
- }
-
- NamedNodeMap var4 = this.fDocumentType.getEntities();
- String var5 = this.fStringPool.toString(var2);
- Node var6 = var4.getNamedItem(var5);
- if (var6 == null || var6.hasChildNodes()) {
- return;
- }
-
- Entity var7 = (Entity)var6;
- if (var3.hasChildNodes()) {
- NodeList var8 = var3.getChildNodes();
- int var9 = var8.getLength();
-
- for(int var10 = 0; var10 < var9; ++var10) {
- Node var11 = var8.item(var10).cloneNode(true);
- var7.appendChild(var11);
- }
-
- return;
- }
- }
- } else if (this.fNodeExpansion == 1) {
- String var12 = this.fStringPool.toString(var2);
- int var13 = this.nodestack[--this.stacktop];
- this.fCurrentNodeIndex = this.nodestack[--this.stacktop];
- if (this.fDeferredDocumentImpl.getNodeType(var13) != 5) {
- return;
- }
-
- var13 = this.fDeferredDocumentImpl.getFirstChild(var13);
- if (this.fDocumentTypeIndex != -1) {
- int var15;
- for(var15 = this.fDeferredDocumentImpl.getFirstChild(this.fDocumentTypeIndex); var15 != -1 && (this.fDeferredDocumentImpl.getNodeType(var15) != 6 || !this.fDeferredDocumentImpl.getNodeNameString(var15).equals(var12)); var15 = this.fDeferredDocumentImpl.getNextSibling(var15)) {
- }
-
- if (var15 != -1 && this.fDeferredDocumentImpl.getFirstChild(var15) == -1) {
- this.fDeferredDocumentImpl.setAsFirstChild(var15, var13);
- }
- }
- }
-
- }
- }
- }
-
- public void characters(int var1, boolean var2) throws Exception {
- if (this.fNodeExpansion == 0) {
- Object var5 = null;
- if (var2) {
- var5 = this.fDocument.createCDATASection(this.fStringPool.orphanString(var1));
- } else {
- Object var4 = null;
- if (this.fWithinElement && this.fCurrentNode.getNodeType() == 1) {
- Node var7 = this.fCurrentNode.getLastChild();
- if (var7 != null && var7.getNodeType() == 3) {
- ((Text)var7).appendData(this.fStringPool.orphanString(var1));
- return;
- }
- }
-
- var5 = this.fDocument.createTextNode(this.fStringPool.orphanString(var1));
- }
-
- if (var5 != null) {
- this.fCurrentNode.appendChild((Node)var5);
- }
- } else {
- if (this.fNodeExpansion == 1) {
- int var3 = var2 ? this.fDeferredDocumentImpl.createCDATASection(var1) : this.fDeferredDocumentImpl.createTextNode(var1, false);
- this.fDeferredDocumentImpl.appendChild(this.fCurrentNodeIndex, var3);
- }
-
- }
- }
-
- public void ignorableWhitespace(int var1, boolean var2) throws Exception {
- if (this.fNodeExpansion == 0) {
- Object var4 = null;
- if (var2) {
- var4 = this.fDocument.createCDATASection(this.fStringPool.orphanString(var1));
- } else {
- var4 = this.fDocument.createTextNode(this.fStringPool.orphanString(var1));
- }
-
- if (var4 != null) {
- if (this.fDocumentImpl != null) {
- ((TextImpl)var4).setIgnorableWhitespace(true);
- }
-
- this.fCurrentNode.appendChild((Node)var4);
- }
- } else {
- if (this.fNodeExpansion == 1) {
- int var3 = var2 ? this.fDeferredDocumentImpl.createCDATASection(var1) : this.fDeferredDocumentImpl.createTextNode(var1, true);
- this.fDeferredDocumentImpl.appendChild(this.fCurrentNodeIndex, var3);
- }
-
- }
- }
-
- public void processingInstruction(int var1, int var2) throws Exception {
- if (this.fNodeExpansion == 0) {
- String var6 = this.fStringPool.orphanString(var1);
- String var4 = this.fStringPool.orphanString(var2);
- ProcessingInstruction var5 = this.fDocument.createProcessingInstruction(var6, var4);
- this.fCurrentNode.appendChild(var5);
- } else {
- if (this.fNodeExpansion == 1) {
- int var3 = this.fDeferredDocumentImpl.createProcessingInstruction(var1, var2);
- this.fDeferredDocumentImpl.appendChild(this.fCurrentNodeIndex, var3);
- }
-
- }
- }
-
- public void comment(int var1) throws Exception {
- if (this.fNodeExpansion == 0) {
- Comment var3 = this.fDocument.createComment(this.fStringPool.orphanString(var1));
- this.fCurrentNode.appendChild(var3);
- } else {
- if (this.fNodeExpansion == 1) {
- int var2 = this.fDeferredDocumentImpl.createComment(var1);
- this.fDeferredDocumentImpl.appendChild(this.fCurrentNodeIndex, var2);
- }
-
- }
- }
-
- public void characters(char[] var1, int var2, int var3, boolean var4) throws Exception {
- }
-
- public void ignorableWhitespace(char[] var1, int var2, int var3, boolean var4) throws Exception {
- }
-
- private void push(int var1) {
- if (this.stacktop == this.nodestack.length) {
- int[] var2 = new int[this.stacktop * 2];
- System.arraycopy(this.nodestack, 0, var2, 0, this.stacktop);
- this.nodestack = var2;
- }
-
- this.nodestack[this.stacktop++] = var1;
- }
-
- private int pop() {
- return this.nodestack[--this.stacktop];
- }
-
- public void parse(InputSource var1) throws SAXException, IOException {
- this.fRootElement = false;
- super.parse(var1);
- if (!this.fRootElement) {
- try {
- ((XMLParser)this).error(118);
- } catch (Exception var3) {
- throw new SAXException(var3);
- }
- }
- }
-
- // $FF: synthetic method
- static Class class$(String var0) {
- try {
- return Class.forName(var0);
- } catch (ClassNotFoundException var2) {
- throw new NoClassDefFoundError(((Throwable)var2).getMessage());
- }
- }
-
- static {
- DEFAULT_DOCUMENT_CLASS = (class$com$ibm$xml$dom$DocumentImpl != null ? class$com$ibm$xml$dom$DocumentImpl : (class$com$ibm$xml$dom$DocumentImpl = class$("com.ibm.xml.dom.DocumentImpl"))).getName();
- }
- }
-